﻿/**
 * Form used for creating and editing Cells
 */
Ext.define('Sisconsolid.view.cell.edit.Form', {
    extend: 'Ext.form.Panel',
    alias: 'widget.cell.edit.form',
    requires: [
        'Ext.form.FieldSet',
		'Ext.form.FieldContainer',
        'Ext.form.field.Date',
        'Ext.form.field.Text',
		'Ext.form.field.ComboBox',
        'Sisconsolid.store.address.Provinces',
		'Sisconsolid.store.address.Cities',
		'Sisconsolid.store.address.Neighborhoods',
		'Sisconsolid.store.address.Streets',
		'Sisconsolid.store.util.CellList',
		'Sisconsolid.store.Families',
		'Sisconsolid.store.Nets',
		'Sisconsolid.store.util.Days',		
		'Sisconsolid.store.util.CellList'
    ],
	bodyPadding: 10,
    initComponent: function() {
        var me = this;
        Ext.applyIf(me, {
            fieldDefaults: {
                allowBlank: false,
                labelAlign: 'top',	
                flex: 1,
				margins: 3
            },
            defaults: {
                layout: 'hbox'
            },
            items: [
                {
                    xtype: 'fieldset',
					title: translations.leader,
					layout: 'anchor',
					defaults: {
						layout: '100%'
					},
                    items: [
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',
							items: [
								{
									xtype: 'textfield',
									name: 'leaderFirstName',
									fieldLabel: translations.firstName,
									maxLength: 100,
									flex: 4
								},
								{
									xtype: 'textfield',
									name: 'leaderLastName',
									fieldLabel: translations.lastName,
									maxLength: 100,
									flex: 4
								},
								{
									xtype: 'textfield',
									name: 'leaderPhone',
									fieldLabel: translations.personalPhone,
									allowBlank: true,
									maxLength: 30,
									flex: 1.75
								}
							]
						}
                    ]
                },
				{
                    xtype: 'fieldset',
					title: translations.cell,
					layout: 'anchor',
					defaults: {
						layout: '100%'
					},
                    items: [
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',
							items: [
								{
									xtype: 'textfield',
									name: 'hostName',
									fieldLabel: translations.hostName,
									maxLength: 100,
									flex: 4
								},
								{
									xtype: 'textfield',
									name: 'cellPhone',
									fieldLabel: translations.cellPhone,
									maxLength: 30,
									flex: 3
								},
								{
									xtype: 'combobox',
									name: 'day',
									fieldLabel: translations.day,
									store: {
										type: 'util.days'
									},
									valueField: 'key',									
									displayField: 'value',									
									editable: false,
									forceSelection: true,
									flex: 2
								},
								{
									xtype: 'textfield',
									name: 'time',
									fieldLabel: translations.time,
									maxLength: 5,
									flex: 1
								},
								{
									xtype: 'datefield',
									name: 'startDate',
									fieldLabel: translations.startDate,
									submitFormat: 'Y-m-d',
									maxValue: new Date(),
									flex: 2									
								}
							]
						}
                    ]
                },
                {
                    xtype: 'fieldset',
					title: translations.address,
					layout: 'anchor',
					defaults: {
						layout: '100%'
					},
                    items: [
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',
							items: [
								{
									xtype: 'ux.form.field.remotecombobox',
									name: 'idProvince',
									fieldLabel: translations.province,
									store: {
										type: 'address.province'
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true,
								},
								{
									xtype: 'combobox',
									name: 'idCity',
									fieldLabel: translations.city,
									store: {
										type: 'address.city',
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true
								},
								{
									xtype: 'ux.form.field.remotecombobox',
									name: 'idNeighborhood',
									fieldLabel: translations.neighborhood,
									store: {
										type: 'address.neighborhood'
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true,
									labelAlign: 'top',
								},
								{
									xtype: 'ux.form.field.remotecombobox',
									name: 'idStreet',
									fieldLabel: translations.street,
									store: {
										type: 'address.street'
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true,
									labelAlign: 'top',
								}
							]
						},
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',
							items: [
								{
									xtype: 'fieldcontainer',
									layout: 'hbox',
									items: [
										{
											xtype: 'numberfield',
											name: 'number',
											fieldLabel: translations.number,
											minValue: 0,
											maxLength: 8,									
											allowBlank: true,
											hideTrigger: true,
											keyNavEnabled: false,
											mouseWheelEnabled: false,
											flex: 3,
										}, 
										{
											xtype: 'hiddenfield',
											flex: 5									
										}
									]
								},
								{
									xtype: 'fieldcontainer',
									layout: 'hbox',
									items: [
										{
											xtype: 'textfield',
											name: 'floor',
											fieldLabel: translations.floor,
											allowBlank: true,
											maxLength: 5,
											flex: 1
										},
										{
											xtype: 'textfield',
											name: 'department',
											fieldLabel: translations.department,
											allowBlank: true,
											maxLength: 5,
											flex: 1
										}, 
										{
											xtype: 'hiddenfield',
											flex: 2									
										}
									]
								},
								{
									xtype: 'fieldcontainer',
									layout: 'hbox',
									items: [
										{	
											xtype: 'textfield',
											name: 'block',
											fieldLabel: translations.block,
											allowBlank: true,
											maxLength: 5,
											flex: 1
										},
										{
											xtype: 'textfield',
											name: 'lot',
											fieldLabel: translations.lot,
											allowBlank: true,
											maxLength: 5,
											flex: 1
										},										
										{
											xtype: 'hiddenfield',
											flex: 2									
										}
									]
								},
								{
									xtype: 'fieldcontainer',
									layout: 'hbox',
									items: [
										{
											xtype: 'textfield',
											name: 'postalCode',
											fieldLabel: translations.postalCode,
											maxLength: 100,
											flex: 1
										},										
										{
											xtype: 'hiddenfield',
											flex: 2									
										}
									]
								}
							]
						}
                    ]
                },
                {
                    xtype: 'fieldset',
					title: translations.ministerial,
					layout: 'anchor',
					defaults: {
						layout: '100%'
					},
                    items: [
						{
							xtype: 'fieldcontainer',
							layout: 'hbox',
							items: [
								{
									xtype: 'combobox',
									name: 'idFamily',
									fieldLabel: translations.family,
									store: {
										type: 'family'
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true,
									flex: 1.5
								},
								{
									xtype: 'combobox',
									name: 'idNet',
									fieldLabel: translations.net,
									store: {
										type: 'net'
									},
									valueField: 'key',									
									displayField: 'value',									
									editable: false,
									forceSelection: true,
									flex: 1.25
								},
								{	
									xtype: 'textfield',
									name: 'cellCode',
									fieldLabel: translations.cellCode,
									maxLength: 5,
									flex: 0.5
								},
								{
									xtype: 'textfield',
									name: 'generation',
									fieldLabel: translations.generation,
									maxLength: 5,
									flex: 2
								},								
								{
									xtype: 'combobox',
									name: 'idMotherCell',
									fieldLabel: translations.motherCell,
									store: {
										type: 'util.cellList'
									},
									valueField: 'key',									
									displayField: 'value',
									editable: false,
									forceSelection: true,
									flex: 2.5
								}
							]
						}
                    ]
                }
            ]
        });
        me.callParent( arguments );
    }
});